/* model */
import Column from '@model/types/Column';
import { isUndefined } from '@src/util/type';
/* vue */
import Vue, { Ref } from 'vue';

function isTableCellInEdit(row: Record<string, any>, column: Column) {
  return isColumnInEdit(column) && isRowInEdit(row);
}

function isTableCellInEditUndefined(row: Record<string, any>, column: Column) {
  return isUndefined(column?.isEdit) && isUndefined(row?.isEdit);
}

function isTableCellInEditNotUndefined(row: Record<string, any>, column: Column) {
  return !isTableCellInEditUndefined(row, column);
}

function isColumnInEdit(column: Column) {
  return Boolean(column?.isEdit);
}

function isRowInEdit(row: Record<string, any>) {
  return Boolean(row?.isEdit);
}

function setTableCellIsEditTrue(row: Record<string, any>, column: Column) {
  setTableCellIsEdit(row, column, true);
}

function setTableCellIsEditFalse(row: Record<string, any>, column: Column) {
  setTableCellIsEdit(row, column, false);
}

function setTableCellIsEdit(row: Record<string, any>, column: Column, isEdit: boolean) {
  setRowIsEdit(row, isEdit);
  setColumnIsEdit(column, isEdit);
}

function setColumnIsEdit(column: Column, isEdit: boolean) {
  if (column) {
    Vue.set(column, 'isEdit', isEdit);
  }
}

function setRowIsEdit(row: Record<string, any>, isEdit: boolean) {
  if (row) {
    Vue.set(row, 'isEdit', isEdit);
  }
}

export {
  isTableCellInEdit,
  isColumnInEdit,
  isRowInEdit,
  setTableCellIsEditTrue,
  setTableCellIsEditFalse,
  setColumnIsEdit,
  setRowIsEdit,
  isTableCellInEditUndefined,
  isTableCellInEditNotUndefined
}
